package com.mfnote.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 获得对应的时间格式的字符串
 * @author DC
 *
 */
public class TimeUtil {
   public static String getPlayTime(long time){
	   String str="00:00:00";
	   if(time==0){
		   str="00:00:00";
	   }
	   else if(time<60){
		   str="00:00:"+(time>=10?time:"0"+time);
	   }else if(time==60){
		   str="00:01:00";
	   }else if(time<3600){
		   long minute = time/60;
		   long second = time%60;
		   str="00:"+(minute>=10?minute:"0"+minute)+":"+(second>=10?second:"0"+second);
	   }else if(time==3600){
		   str="01:00:00";
	   }else if(time>3600){
		   long hour = time/3600;
		   long minute = (time-hour*3600)/60;
		   long second = time%60;
		   str=""+(hour>=10?hour:"0"+hour)+":"+(minute>=10?minute:"0"+minute)+":"+(second>=10?second:"0"+second);
	   }
	   return str;
   }
   
   public static String getRecordTime(long time){
	   String str="00:00";
	   if(time==0){
		   str="00:00";
	   }
	   else if(time<60){
		   str="00:"+(time>=10?time:"0"+time);
	   }else if(time==60){
		   str="01:00";
	   }else if(time<3600){
		   long minute = time/60;
		   long second = time%60;
		   str=""+(minute>=10?minute:"0"+minute)+":"+(second>=10?second:"0"+second);
	   }else if(time==3600){
		   str="01:00:00";
	   }else if(time>3600){
		   long hour = time/3600;
		   long minute = (time-hour*3600)/60;
		   long second = time%60;
		   str=""+(hour>=10?hour:"0"+hour)+":"+(minute>=10?minute:"0"+minute)+":"+(second>=10?second:"0"+second);
	   }
	   return str;
   }

   /**
    * 获取时间差
    * @param before 先前记事时间
    * @param today 当前时间
    * @return
    * @throws ParseException
    */
   public static long compareTime(String before,String today) throws ParseException {
	   SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	   Date begin=dfs.parse(before);//先前记事时间
	   Date end = dfs.parse(today);//当前时间

	   long between=(end.getTime()-begin.getTime())/1000;//除以1000是为了转换成秒

	   long day1=between/(24*3600);

//	   long hour1=between%(24*3600)/3600;
//
//	   long minute1=between%3600/60;
//
//	   long second1=between%60/60;
	   
	   return  day1;  
	
   }
}
